<template>
  <div>
    <el-form ref="elForm" :model="formData" :rules="rules" size="small" label-width="100px"
      label-position="top">
      <el-row gutter="15">
      </el-row>
      <el-row gutter="15">
      </el-row>
      <el-form-item label="姓名" prop="name">
        <el-input v-model="formData.name" placeholder="真实姓名，中文" :maxlength="8" clearable
          :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="手机" prop="phone">
        <el-input v-model="formData.phone" placeholder="请输入手机号码" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="formData.email" placeholder="xxxxxx@email.com" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="身份证" prop="idcard">
        <el-input v-model="formData.idcard" placeholder="18位身份证号码" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="教育程度" prop="education">
        <el-select v-model="formData.education" placeholder="请选择教育程度" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in educationOptions" :key="index" :label="item.label"
            :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="省份" prop="province">
        <el-select v-model="formData.province" placeholder="请选择省份" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in provinceOptions" :key="index" :label="item.label"
            :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="通讯地址" prop="address">
        <el-input v-model="formData.address" placeholder="请输入通讯地址" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="微信" prop="weChat">
        <el-input v-model="formData.weChat" placeholder="请输入微信" clearable :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="报考院校" prop="field117">
        <el-select v-model="formData.field117" placeholder="请选择报考院校" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in field117Options" :key="index" :label="item.label"
            :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="报考专业" prop="field118">
        <el-input v-model="formData.field118" placeholder="请输入报考专业" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="身份证正面照" prop="field119" required>
        <el-upload ref="field119" :file-list="field119fileList" :action="field119Action"
          :before-upload="field119BeforeUpload" list-type="picture-card">
          <i class="el-icon-plus"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="身份证背面照" prop="field120" required>
        <el-upload ref="field120" :file-list="field120fileList" :action="field120Action"
          :before-upload="field120BeforeUpload" list-type="picture-card">
          <i class="el-icon-plus"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="毕业照片" prop="field121" required>
        <el-upload ref="field121" :file-list="field121fileList" :action="field121Action"
          :before-upload="field121BeforeUpload" list-type="picture-card">
          <i class="el-icon-plus"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="电子版照片" prop="field122" required>
        <el-upload ref="field122" :file-list="field122fileList" :action="field122Action"
          :before-upload="field122BeforeUpload" list-type="picture-card">
          <i class="el-icon-plus"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="多选框组" prop="field123">
        <el-checkbox-group v-model="formData.field123" size="medium">
          <el-checkbox v-for="(item, index) in field123Options" :key="index" :label="item.value"
            :disabled="item.disabled">{{item.label}}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        name: undefined,
        phone: undefined,
        email: undefined,
        idcard: '',
        education: '高中',
        province: '北京市',
        address: undefined,
        weChat: undefined,
        field117: 1,
        field118: undefined,
        field119: null,
        field120: null,
        field121: null,
        field122: null,
        field123: [],
      },
      rules: {
        name: [{
          required: true,
          message: '真实姓名，中文',
          trigger: 'blur'
        }],
        phone: [{
          required: true,
          message: '请输入手机号码',
          trigger: 'blur'
        }],
        email: [{
          required: true,
          message: 'xxxxxx@email.com',
          trigger: 'blur'
        }],
        idcard: [{
          required: true,
          message: '18位身份证号码',
          trigger: 'blur'
        }],
        education: [{
          required: true,
          message: '请选择教育程度',
          trigger: 'change'
        }],
        province: [{
          required: true,
          message: '请选择省份',
          trigger: 'change'
        }],
        address: [{
          required: true,
          message: '请输入通讯地址',
          trigger: 'blur'
        }],
        weChat: [{
          required: true,
          message: '请输入微信',
          trigger: 'blur'
        }],
        field117: [{
          required: true,
          message: '请选择报考院校',
          trigger: 'change'
        }],
        field118: [{
          required: true,
          message: '请输入报考专业',
          trigger: 'blur'
        }],
        field123: [{
          required: true,
          type: 'array',
          message: '请至少选择一个field123',
          trigger: 'change'
        }],
      },
      field119Action: 'https://jsonplaceholder.typicode.com/posts/',
      field119fileList: [],
      field120Action: 'https://jsonplaceholder.typicode.com/posts/',
      field120fileList: [],
      field121Action: 'https://jsonplaceholder.typicode.com/posts/',
      field121fileList: [],
      field122Action: 'https://jsonplaceholder.typicode.com/posts/',
      field122fileList: [],
      educationOptions: [{
        "label": "高中",
        "value": "高中"
      }, {
        "label": "大专",
        "value": "大专"
      }, {
        "label": "本科",
        "value": "本科"
      }],
      provinceOptions: [{
        "label": "北京市",
        "value": "北京市"
      }, {
        "label": "上海市",
        "value": "上海市"
      }],
      field117Options: [{
        "label": "河北经贸大学",
        "value": 1
      }, {
        "label": "天津师范大学",
        "value": 2
      }],
      field123Options: [{
        "label": "本人已核实，确认信息真实无误",
        "value": 1
      }],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        // TODO 提交表单
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
    field119BeforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 2
      if (!isRightSize) {
        this.$message.error('文件大小超过 2MB')
      }
      return isRightSize
    },
    field120BeforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 2
      if (!isRightSize) {
        this.$message.error('文件大小超过 2MB')
      }
      return isRightSize
    },
    field121BeforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 2
      if (!isRightSize) {
        this.$message.error('文件大小超过 2MB')
      }
      return isRightSize
    },
    field122BeforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 2
      if (!isRightSize) {
        this.$message.error('文件大小超过 2MB')
      }
      return isRightSize
    },
  }
}

</script>
<style>
.el-upload__tip {
  line-height: 1.2;
}

</style>
